﻿using DevExpress.XtraReports.UI;
using DevTeam;
using System;
using System.Drawing;

namespace ConfExpert.Forms.Rapor
{
    public partial class AksesuarIrsaliyeLines : DevExpress.XtraReports.UI.XtraReport
    {
        public AksesuarIrsaliyeLines()
        {
            InitializeComponent();
        }
        public void fillTables(string TalepId, string IrsaliyeNo, DateTime sevkTarihi, string details)
        {
            myDataIrsaliye.Merge(Session.DataManager.ExecuteDataSet("GetAksesuarIrsaliye", TalepId, IrsaliyeNo, sevkTarihi, details));
            myDataIrsaliye.AksesuarIrsaliye.Merge(myDataIrsaliye.Tables["Table"]);
            myDataIrsaliye.AksesuarIrsaliyeLines.Merge(myDataIrsaliye.Tables["Table1"]);
        }

        private void xrTableCell7_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            ReSize(sender, 8, FontStyle.Regular);
        }

        private void ReSize(object sender, float newSize, FontStyle fontstyle)
        {
            //Resize ı düzgün yapan tek fonksiyon !!!
            Graphics gr = Graphics.FromHwnd(IntPtr.Zero);
            gr.PageUnit = GraphicsUnit.Millimeter;
            int factor = 10;

            XRLabel label = (XRLabel)sender;

            //float newSize = 8f;
            Font defaultFont = new System.Drawing.Font("Times New Roman", newSize, fontstyle);

            float stringWidth = gr.MeasureString(label.Text, defaultFont).Width;
            float labelWidth = label.WidthF;


            if (labelWidth < stringWidth * factor)
                newSize = defaultFont.Size * label.WidthF / stringWidth / factor;


            label.Font = new Font(defaultFont.FontFamily, newSize, fontstyle);
            gr.Dispose();
        }
    }
}
